/*************************************************************************
	> File Name: web.h
	> Author: ma6174
	> Mail: ma6174@163.com 
	> Created Time: 2021年12月10日 星期五 21时39分06秒
 ************************************************************************/

#include<iostream>
#include <string>
#include <unordered_map>

//用户类
class User
{
public:
	User() = default;
	User(std::string n) : name(n) {}

	void setName(std::string n)
	{
		name = n;
	}

	std::string getName()
	{
		return name;
	}

private:
	std::string name;
};

//网站抽象类
class WebSite
{
public:
	virtual void use(User user) = 0;
};

//网站具体类
class ConcreteWebSite : public WebSite
{
public:
	ConcreteWebSite() = default;
	ConcreteWebSite(std::string n) : name(n) {}

	virtual void use(User user)
	{
		std::cout << "网站分类:\t" << name << "\t用户:\t" << user.getName() << std::endl;
	}

private:
	std::string name;
};

//网站工厂类
class WebSiteFactory
{
public:
	WebSite* getWebSiteCategory(std::string key)
	{
		if (flyweights.find(key) == flyweights.end())
			flyweights.insert(std::make_pair(key, new ConcreteWebSite(key)));
		return flyweights.at(key);
	}

	int getWebSiteCount()
	{
		return flyweights.size();
	}

private:
	std::unordered_map<std::string, WebSite*> flyweights;
};
